﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.Service.System;
using WMS.FC.Domain.Service.Tray.Interface;

namespace WMS.FC.Domain.Service.Tray
{
    public class GetTrayProductLineService : ServiceBase, IGetTrayProductLineService
    {
        public GetTrayProductLineService(
            ILogger<ServiceBase> logger,
            IOptions<WmsSettings> options,
            IMapper mapper)
            : base(logger, options, mapper)
        {
        }

        public async Task<ActionResult<string>> GetTrayProductLine(string trayBarcode)
        {
            return await Task.Run(() =>
            {
                var result = new ActionResult<string>("获取托盘产线");
                try
                {
                    if (string.IsNullOrWhiteSpace(trayBarcode))
                        return result.ArgumentError("托盘条码不能为空");

                    result.Data = $"Line_{trayBarcode.Substring(3, 1)}";
                }
                catch (Exception ex)
                {
                    return result.Exception(ex);
                }

                return result;
            });
        }
    }
}
